home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / MISC / HTC81.ZIP / HOWTO8_1.TXT
Encoding:
Text File  |  1996-05-18  |  17.2 KB  |  326 lines

  1.  
  2. HOW TO CRACK, by +ORC, A TUTORIAL
  3.  
  4. Lesson 8.1: How to crack Windows, an approach 
  5.  
  6. --------------------------------------------------------
  7.      SPECIAL NOTE: Please excuse the somehow "unshaven"
  8.      character of the windows lessons... I'm cracking the
  9.      newest Windows '95 applications right now, therefore
  10.      at times I had to add "on the fly" some corrections to
  11.      the older Windows 3.1 and Windows NT findings.
  12.                 "homines, dum docent, discunt".
  13. ---------------------------------------------------------
  14.  
  15. ->   1st THING TO REMEMBER 
  16. The NE format does give every windows executable the equivalent
  17. of a debug symbol table: A CRACKER BLISS!
  18.  
  19. ->   UNDOCUMENTED DEBUGGING
  20. One of the many feature of Windows based on undocumented
  21. foundations is the "ability to debug". 
  22. A word about undocumented functions in the MS-Operating Systems:
  23. Microsoft manipulates its rule and domination of the operating
  24. systems in use to day (MS-DOS, Windows, Windows '95) with two
  25. main wicked aims:
  26. 1)   getting the concurrence completely bankrupt (that's the
  27.      scope of all the using of undocumented functions and
  28.      CHANGING them as soon as the concurrence uses them). The
  29.      battle against Borland was fought in this way.
  30. 2)   getting all future "programmers" to use windows as a "black
  31.      box" that only Microsoft engineers (if ever) can master, so
  32.      that everybody will have to sip the ill-cooked abominations
  33.      from Microsoft without ever having a chance to alter or
  34.      ameliorate them.
  35. Strange as it may seem, only the sublime cracker community fights
  36. against these intolerable plans. All stupid governments and
  37. lobbies -on the contrary- hide behind the fig-leaf of the
  38. "market" "freedom" in order to ALLOW such heinous developments
  39. (I'm speaking as if they were capable to opposing them even if
  40. they wanted, which they do not. Be assured, they couldn't anyway,
  41. "Governments" are deliberately MADE to serve Gates and all the
  42. remaining suckers, and lobbies are the shield of feudalism. You
  43. can forget "democracy", the only rule existing is a malevolent
  44. oligarchy based on money, personal connections, defect of
  45. culture, lack of knowledge and dictatorship of bad taste through
  46. television in order to keep the slaves tamed... enough now...)
  47. The windows situation is particularly reminiscent of the older
  48. situation in DOS, where for years the key "load but don't
  49. execute" function, used by debuggers, such as [DEBUG], [SYMDEB]
  50. and [CODEVIEW], was "reserved" by Microsoft.
  51.      The windows debugging library, WINDEBUG.DLL, a number of
  52. undocumented functions and even the interface it provides are
  53. undocumented! The WinDebug() function is used by all available
  54. windows debuggers, including [CVW] (CodeView for Windows), [TDW]
  55. (TurboDebugger for Windows), [Multiscope] and [Quick C for
  56. Windows] (the last two are GUI, not text debuggers. The use of
  57. WinDebug() doesn't show up in MAPWIN output 'coz debuggers link
  58. to it at run-time via the amazing GetProcAddress() function.
  59.      WinDebug() is a hacked 32-bit version, for the old Windows
  60. 3.0, of the poorly documented DOSPTrace() function from OS/2 1.x
  61. (study these older Operating Systems! Studying the past you'll
  62. understand EVERYTHING! Sometime I think that the only way to hack
  63. and crack correctly is to be more a software historian than a
  64. programmer... fac sapias et liber eris!). DOSPTrace is, in turn,
  65. based on the ptrace() function in Unix.
  66.      Like DosPTrace(), WinDebug() takes commands such as Go,
  67. Single-Step, Write&Read Registers, Write&Read Memory. It returns
  68. to its caller either when the command completes or when a
  69. breakpoint occurs (or a DLL load). These commands and
  70. notifications appear in a large structure whose address is passed
  71. in WinDebug().
  72.      WinDebug() was renamed CVWIN.DLL (and TDWIN.DLL) for Windows
  73. 3.1., all crackers should study it and get the maximum possible
  74. documentation about it. As you will see in the following, it is
  75. worth to study also TOOLHELP.DLL (what Microsoft would like you
  76. to fiddle with) and INT_41h (the real debugging interface).
  77.  
  78. Interrupt handling under Windows
  79.      Interrupt handling under Windows can be tricky: you need to
  80. use Toolhelp (a rather scaring lobotomy for your programs) or to
  81. have special code for Standard vs. Enhanced modes, because the
  82. information on the stack of an interrupt or exception handler
  83. differs between the two windows modes. In addition, some handlers
  84. would be installed using INT_21h, while others are set up using
  85. DPMI services. Toolhelp has quite a bit of internal code that
  86. "cooks" the interrupts and sends them to you in an easily
  87. digestible form. 
  88.      Remember that Windows uses GP faults as a "hacker" method
  89. of doing ring transitions that are not allowed with legal 80x86
  90. instructions: the virtual memory system of Enhanced mode is
  91. implemented via the page fault.
  92.  
  93. Some tools for cracking windows (-> see lesson 9)
  94. -----------------          DEBUGGERS
  95. CVW and TDW         (you have to know the function's
  96.                     segment:offset address beforehand in order
  97.                     to crack a function)
  98. WCB                 [Windows Codeback] by Leslie Pusztai (it's
  99.                     a really cool tool!)
  100. WDEB386             Microsoft's WDEB386 (clumsy, and requires a
  101.                     second monitor)
  102. Soft-Ice/Windows    best (BY FAR!) windows debugger! NuMega is
  103.                     so good I am at times really sorry to crack
  104.                     their products! [WINICE] is the single,
  105.                     absolutely essential debugger and snooping
  106.                     utility for windows crackers. Get it!
  107.  
  108. -----------------   POST MORTEM INSPECTORS
  109. CORONER, etc.            (a lot of shareware)
  110. MS-DrWatson              Old and clumsy
  111. Borland's Winspector     THE BEST! It has the BUILDSYM utility
  112.                          that allows the creation of a debug
  113.                          .SYM file from an .EXE without debug
  114.                          information.
  115.  
  116.  
  117. -----------------         INSPECTORS
  118. MS-Spy                   Old
  119. Borland's WinSight       (Best one, select "Other")
  120. MicroQuill's Windows DeMystifiers (from Jeff Richter):
  121.      VOYEUR (hold SHIFT picking Message Selection), COLONEL,
  122.      MECHANIC and ECOLOGIST
  123.  
  124. -----------------          SNOOPERS
  125. [INFSPY.EXE], 231.424 bytes, version 2.05 28/8/1994 by Dean
  126. Software Design, may be the more complete one.
  127. [SUPERSPY.EXE], 24.576 bytes, 10,6,1994, quite handy for quick
  128. informations.
  129. [WINVIEW.EXE], 30.832 bytes, Version 3.00 by Scott McCraw, MS(c)
  130. 1990-1992, this is the old MS-Spy, distributed by MS
  131. [TPWSPY.EXE], 9.472 bytes, quite primitive, but you get the
  132. pascal source code with it.
  133.  
  134.  
  135. ->   INSIDE A WINDOWS '95 DEBUGGER
  136.      You can debug a program at the assembly-language level
  137. without any debugging information. The DOS [DEBUG] program does
  138. that, allowing breakpoints and single-stepping, all of which
  139. implies that the hardware must be cooperating. Back in the time
  140. of the 4-MHz Z-80s, you used a debugger that plugged interrupt
  141. op codes into the instruction stream to generate breakpoints.
  142.      Nothing has changed. That's how you debug a program on a
  143. 80586 (=Pentium). The x86 architecture includes software
  144. interrupts. The 1-byte op code xCC is the INT_03 instruction,
  145. reserved for debuggers. You can put the INT_03 op code in place
  146. of the program instruction op code where the break is to occur
  147. and replace the original op code at the time of the interrupt.
  148. In the 80386 and later, you can set a register flag that tells
  149. the processor to generate a not-intrusive INT_01 instruction for
  150. every machine instruction executed. That device supports single
  151. stepping.
  152.      The Win32SDK (Windows '95 software developer's kit) includes
  153. functions that allow one program to launch another program and
  154. debug it. The SDK's debug API takes care of how the interrupts
  155. and interrupt vectors get managed. The logical consequence of
  156. such an approach is that fewer and fewer people will be able to
  157. know what's going on inside an application. The bulk of the
  158. programmers -in few years time- will not be able any more to
  159. reverse engineer an application, unless the few that will still
  160. understand assembler-language do offer them the tools to do it.
  161. Microsoft -it is evident- would like the programmers to use a
  162. "black box" approach to programming, writing nice little "hallo
  163. world" application and leaving to the engineers in Microsoft
  164. alone the capacity to push forward (and sell) real programs that
  165. are not toy application.
  166.      The Win32 documentation seems vast, almost luxurious, until
  167. you begin serious work and you discover its shortcomings, like
  168. the fact that extended error codes are not documented, and
  169. numerous APIs are documented either incorrectly or so poorly that
  170. you must burn precious time testing them. What we definitely need
  171. is to find some secret fellows inside Microsoft (like good old
  172. Prometeus) that smuggles to the outside the real documentation
  173. that the Microsoft engineers have reserved for themselves. If you
  174. are reading this and do work for Microsoft, consider the
  175. possibility of double-crossing your masters for the sake of
  176. humanity and smuggle us the secret information.
  177.      In windows '95 a debugger program launches a program to be
  178. debugged by calling the _CreateProcess function, specifying in
  179. an argument that the program is to be debugged. Then the debugger
  180. program enters a loop to run the program. At the top of the loop
  181. the debugger calls _WaitForDebugEvent.
  182.      Each time _WaitForDebugEvent returns it sets indicators that
  183. tell about the vent that suspended the program being debugged.
  184. This is where the debugger traps breakpoints and single-step
  185. exceptions. _WaitForDebugEvent fills in an event structure that
  186. contains among other things the address that was interrupted end
  187. the event that caused the interrupt.
  188.      The debugger calls _GetThreadContext to get the running
  189. context of the debugged program, including the contents of the
  190. registers. The debugger can, as the result of cracker
  191. interaction, modify these values and the contents of the debugged
  192. program's memory.
  193.      The debugger sets breakpoints by saving the op code at the
  194. instruction to be intercepted and putting the INT_03 op code at
  195. its place, it's always the same old marmalade. When the
  196. breakpoint occurs, the debugger replaces the original op code in
  197. the program's instruction memory, and decrements the interrupted
  198. program counter in the saved context so that execution resumes
  199. at the instruction that was broken.
  200.      To single-step a program, the debugger sets a bit in the
  201. context's flags register that tells the processor to generate an
  202. INT_01 for every instruction cycle. When that interrupt occurs,
  203. the debugger checks to see if the interrupted address is at a new
  204. source-code line number. If not, the debugger continues
  205. execution. Otherwise, the debugger displays the new line in the
  206. IDE and waits for the cracker to take an action that resumes the
  207. program.
  208.      While the debugged program is suspended, the debugger
  209. interacts with the cracker and provides full access to the
  210. debugged program's context and memory. This access permits the
  211. cracker to examine and modify part of the code.
  212.      To resume the debugged program, the debugger resets the
  213. program's context by calling _SetThreadContext and calls
  214. _ContinueDebugEvent. Then, the debugger returns to the top of the
  215. loop to call _WaitForDebugEvent again.
  216.      To extract debug information from a Win32 executable file,
  217. you must understand the format of that file (best thing to do,
  218. to practice yourself, would be to reverse engineer small
  219. programs). The executable file has two sections not found in
  220. other executable files: ".stab" and ".stabstr". How nice that
  221. they used names that suggest their purpose (nomen est omen).
  222. You'll find them inside a table of fixed-length entries that
  223. include entries for .text, .bss, .data and .idata. Inside these
  224. sections the compilers put different parts of a program.
  225.      There are several different formats for encoding debug
  226. information in an executable file. Borland's Turbo Debugger  one
  227. format. Microsoft's CodeView  another. The gnu-win32 port from
  228. Cygnus the stab format, an acronym meaning "symbol table",
  229. although the table contains much more than just symbol
  230. information.
  231.      The .stab section in a portable executable file is a table
  232. of fixed-length entries that represent debugging information in
  233. the stab format. The .stabstr section contains variable-length,
  234. null terminated strings into which the .stab table entries point.
  235.      The documentation for the stab format is available in text
  236. format on the Cygnus ftp site (ftp.cygnus.com//pub/gnu-win32).
  237.      Stabs contain, in a most cryptic format, the names and
  238. characteristics of all intrinsic and user-defined types, the
  239. memory address of every symbol in external memory and on the
  240. stack, the program counter address of every function, the program
  241. counter address where every brace-surrounded statement block
  242. starts and ends, the memory address of line numbers within
  243. source-code files, and anything else that a debugger needs. The
  244. format is complex and cryptic because it is intended to support
  245. any source-code language. It is the responsibility of a debugger
  246. program to translate the stab entries into something meaningful
  247. to the debugger in the language being debugged.
  248.  
  249.      Windows '95 invokes dozens of INT_21 services from 32-bit
  250. code, including KERNEL32.DLL and possess Krn32Mutex, which
  251. apparently controls access to certain parts of the kernel. Some
  252. of the functions in KERNEL32 can be blocked by the Win16Mutex,
  253. even though Microsoft says this isn't the case.
  254.  
  255. SO, I WANNA CRACK, WHAT SHOULD I DO?
  256.      I'll show you a simple windows crack, so easy it can be done
  257. without WINICE: let's take [WINPGP4.1.] (front-end for PGPing in
  258. windows, by Geib - I must thank "Q" for the idea to work on this
  259. crack).   
  260.      Using WCB you'll find out quickly that the "CONGRATULATIONS
  261. your registration number is OK" and the "SORRY, your registration
  262. number is not correct" data blocks are at the block starting at
  263. 36.38B8 (respectively at 36.38D5 and 36.3937), that relocs to
  264. 13.081B.
  265.      Looking at 13.0000 and following code, you'll find a push
  266. 38D5 (68D538) and a push 3937 (683739) at 13.064D and 13.06AE. 
  267.      The road to the crack is now open, you just need to find and
  268. "fool" the calling routines. You'll learn the exact procedures
  269. for this kind of WINcracks in part 2 and 3 of -> Lesson 8. Let's
  270. now have a look at the protection scheme (disassembly from WCB):
  271. ...
  272. 13.0E88   660FBF46F8     movsx     eax, word ptr [bp-08]
  273. 13.0E8D   668946F4       mov       [bp-0C], eax
  274. 13.0E91   668B46F4       mov       eax, [bp-0C]
  275. 13.0E95   6669C00A000300 imul      eax, 0003000A
  276. 13.0E9C   668946F0       mov       [bp-10], eax
  277. 13.0EA0   668B4606       mov       eax, [bp+06]
  278. 13.0EA4   663B46F0       cmp       eax, [bp-10]
  279. 13.0EA8   7505           jne       0EAF      <- beggar_off
  280. 13.0EAA   B80100         mov       ax, 0001  <- flag 1 = "Right!"
  281. 13.0EAD   EB04           jmp       0EB3      <- and go on
  282. beggar_off:
  283. 13.0EAF   33C0           xor       ax,ax     <- flag 0 = "Nope!"
  284. 13.0EB1   EB00           jmp       0EB3      <- and go on
  285.  
  286.      I want you to have a good look at this protection scheme.
  287. IT'S THE SAME OLD SOUP! You do remember lesson 3 and the
  288. protection schemes of the old DOS stupid games of the '80s, don't
  289. you? IT'S THE SAME OLD SOUP! In this "up-to-date" "new" windows
  290. application, in WINPGP version 4.1 of 1995/1996, exactly the same
  291. kind of protection is used to "conceal" the password! 
  292. A)   compare user input with memory echo
  293. B)   beggar off if not equal with AX=0
  294. C)   go on if equal with AX=1... how boring!
  295.      Besides, look at all the mov eax, and  eax, moves preceding
  296. the compare! That's a typical pattern for these "number_password"
  297. protections! I wrote (years ago) a little crack utility that
  298. searches for code blocks with a "66" as first instruction_byte
  299. repeating in four or more consecutive instructions and it still
  300. allows me to crack more than half of these windows password smuts
  301. in less than three seconds flat. The IMUL instruction creates the
  302. "magic" number, and if you give a closer look at the mathematical
  303. part of the "conceal" routine, it could help you to crack
  304. analogous schemes used in order to protect the "Instant access"
  305. (c) & (tm) time_crippled software :=)
  306.      Now you could crack the above code in 101 different ways,
  307. the most elegant one would probably substitute je 0EAF (or jZ
  308. 0EAF, that's the same) to the jne 0EAF at 13.0EA8. You just write
  309. a 74 at the place of the 75, like you did for the cracks in
  310. 1978... how boring: it's really the same old soup! (But you'll
  311. see some new tricks in the next lessons).
  312.  
  313. Well, that's it for this lesson, reader. Not all lessons of my
  314. tutorial are on the Web.
  315.      You 'll obtain the missing lessons IF AND ONLY IF you mail
  316. me back (via anon.penet.fi) with some tricks of the trade I may
  317. not know that YOU discovered. Mostly I'll actually know them
  318. already, but if they are really new you'll be given full credit,
  319. and even if they are not, should I judge that you "rediscovered"
  320. them with your work, or that you actually did good work on them,
  321. I'll send you the remaining lessons nevertheless. Your
  322. suggestions and critics on the whole crap I wrote are also
  323. welcomed.
  324.  
  325. +ORC  526164@anon.penet.fi 
  326.